<template>
  <!-- 核保记录页面 -->
  <div class="fillcontain">
    <el-form
      :model="searchParams"
      ref="ruleForm"
      label-width="100px"
      class="search_container"
    >
      <el-row>
        <el-col :span="6">
          <el-form-item label="保单号：" class="text_center">
            <el-input
              v-model="searchParams.chdrNum"
              placeholder="请输入"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="受理号：" class="text_center">
            <el-input
              v-model="searchParams.applNum"
              placeholder="请输入"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="客户名称：" class="text_center">
            <el-input
              v-model="searchParams.name"
              placeholder="请输入"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6" class="text_center">
          <el-form-item label="状态：">
            <el-select
              v-model="searchParams.taskStatus"
              placeholder="请选择"
              clearable
            >
              <el-option
                v-for="item in statusDic"
                :key="item.id"
                :label="item.dictValue"
                :value="item.remark"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="6" class="text_center">
          <el-button
            type="primary"
            icon="el-icon-search"
            @click="getList('resetPage')"
          ></el-button>
          <el-button
            type="primary"
            plain
            icon="el-icon-refresh"
            @click="resetSearch"
          ></el-button>
        </el-col>
      </el-row>
    </el-form>

    <div class="contain">
      <div class="table_container">
        <el-table
          :data="tableData"
          highlight-current-row
          height="calc(100vh - 370px)"
          header-cell-class-name="table-header-class"
          style="width: 100%"
        >
          <el-table-column
            min-width="120"
            property="accepted"
            label="受理号"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>

          <el-table-column
            min-width="120"
            property="chdrNum"
            label="保单号"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>

          <el-table-column
            min-width="120"
            property="itemNo"
            label="子任务号"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>

          <el-table-column
            min-width="150"
            property="underwritingFlow"
            label="流水号"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>

          <el-table-column
            min-width="120"
            property="name"
            label="客户名称"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>

          <el-table-column
            min-width="120"
            property="clientType"
            label="客户类型"
            align="center"
            show-overflow-tooltip
          >
          <template slot-scope="scope">
            <div>{{!scope.row.clientType ? '' : scope.row.clientType == '1' ? '投保人' : scope.row.clientType == '2' ? '被保人' : '投被保人'}}</div>
          </template>
          </el-table-column>

          <el-table-column
            min-width="120"
            property="userId"
            label="操作人"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>

          <el-table-column
            min-width="120"
            property="recordTime"
            label="接收日期"
            align="center"
            sortable
            show-overflow-tooltip
          >
          </el-table-column>

          <el-table-column
            min-width="120"
            property="taskStatus"
            label="任务状态"
            align="center"
            show-overflow-tooltip
          >
          <template slot-scope="scope">
            <span>{{ scope.row.taskStatus | formatDict(statusDic,'remark')}}</span>
          </template>
          </el-table-column>

          <el-table-column
            min-width="120"
            property="underwriting"
            label="核保结论"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>

          <el-table-column label="操作" align="center" width="150" fixed="right">
            <template slot-scope="scope">
              <div style="display: flex; justify-content: center">
                <span
                  :class="['handle-btn',{'handle-btn_disable': scope.row.taskStatus != '4'}]"
                  @click="handleDetail(scope.row)"
                  >核保详情</span
                >
                <span
                  class="handle-btn"
                  @click="handleRecord(scope.row)"
                  >体检记录</span
                >
              </div>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页 -->
				<el-row>
					<el-col :span="24">
						<div class="pagination">
							<el-pagination background v-if='paginations.total > 0' :page-sizes="paginations.pageSizes"
								:page-size="paginations.pageSize" :layout="paginations.layout"
								:total="paginations.total" :current-page='paginations.pageIndex'
								@current-change='handleCurrentChange' @size-change='handleSizeChange'>
							</el-pagination>
						</div>
					</el-col>
				</el-row>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getAiTaskRecordApi
} from "@/api/underwriting/uw"
import constant from "@/utils/constant";

import {
  getCodeDictProjectApi
} from "@/api/medicalLibrary/examProjectLibrary";

import mixins from '@/utils/mixins'

export default {
  mixins: [mixins],
  data() {
    return {
      statusDic: [],  //发布状态
      searchParams: {
        applNum: '',
        chdrNum: '',
        name: '',
        pageNum: ''
      },
      tableData: [],
      // 分页
      paginations: {
				total: 0, // 总数
				pageIndex: 1, // 当前位于哪页
				pageSize: 10, // 1页显示多少条
				pageSizes: [10, 20, 30, 50], //每页显示多少条
				layout: "total, sizes, prev, pager, next, jumper" // 翻页属性
			},
    };
  },
  created() {
    this.getList();
    this.getCodeDictProject()
  },
  mounted() { },
  methods: {
    // 查询逻辑符
    getCodeDictProject(){
      getCodeDictProjectApi({code: 'underwritingType'}).then(res => {
				if (res.resultCode == constant.SUCCESS) {
					this.statusDic = res.data
				}
			})
    },
    // 查询列表
    getList(flag) {
      if(flag) this.paginations.pageIndex = 1;
      this.paginations.total = 0;
      let params = {
        pageNum: this.paginations.pageIndex,
        pageSize: this.paginations.pageSize
      }
      for (let key in this.searchParams) {
        if(this.searchParams[key]) params[key] = this.searchParams[key]
      }

      this.$store.dispatch("loading/CHANGE_LOADING", true);
      this.tableData = []
      getAiTaskRecordApi(params).then((res) => {
        this.$store.dispatch("loading/CHANGE_LOADING", false);
        if(res.resultCode == constant.SUCCESS) this.tableData = res.data.list || []
        // 页码赋值
				this.paginations.total = res.data.total;
      })
      .catch((err) => {
        this.$store.dispatch("loading/CHANGE_LOADING", false);
      });
    },
    // 清除查询条件
    resetSearch() {
      this.searchParams = {
        applNum: '',
        chdrNum: '',
        name: '',
        pageNum: ''
      }
    },

    // ----列表操作按钮
    // 核保详情
    handleDetail(row){
      if(row.taskStatus != '4') return
      sessionStorage.setItem('underwritingDetailInfo',JSON.stringify(row))
      this.$router.push({
        path: "/home/maintenance/robouUnderwriting/intelligenceRule/underwritingDetail"
      })
    },
    // 体检记录
    handleRecord(row){
      // 先写死假数据
      let extractResultQuery = {
        itemId: row.itemId,
        mainId: row.mainId,
        peOrgCode: row.peOrgCode,
        accepted: row.accepted,
        peCode: row.peCode,
        itemStatus: row.taskStatus,
        taskNo: row.itemNo,
      }
      sessionStorage.setItem('physicalRecordInfo',JSON.stringify(extractResultQuery))
      this.$router.push({
        path: "/home/maintenance/robouUnderwriting/intelligenceRule/physicalRecord"
      })
    },
    // 每页多少条切换
		handleSizeChange(pageSize) {
			this.paginations.pageSize = pageSize;
			this.getList();
		},
		// 上下分页
		handleCurrentChange(page) {
			this.paginations.pageIndex = page;
			this.getList();
		},
  },
};
</script>

<style lang="less" scoped>
.fillcontain {
  padding-bottom: 0;
}
.contain {
  background: #fff;
  padding: 10px;
  margin-bottom: 20px;
}
.pagination {
  padding: 10px 20px;
  text-align: right;
}
.operationIcon {
  // padding: 12px;
  border: 1px solid #e5e5e5;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: inline-block;
  cursor: pointer;
  box-shadow: 0 0 3px #f9f9f9;
  .svg-icon {
    font-size: 14px;
    fill: #68a3fc;
  }
}
.search_container {
  padding: 20px 20px 0 20px;
}
.handle-btn{
  cursor: pointer;
  color: #409eff;
  display: inline-block;
  padding: 0 8px;
}
.handle-btn_disable{
  cursor: no-drop;
  color: #bbb;
}
</style>



